# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=gtk-vnc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.1
pkgrel=2
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
pkgdesc="VNC viewer widget for GTK+ (mingw-w64)"
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-cyrus-sasl"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-libgpg-error"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-vala")
options=('strip' 'staticlibs')
license=("GPL 2.1")
url="https://www.gnome.org"
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        gvncviewer-1.2.0.patch
        001-fix-keymapgen-call.patch)
sha256sums=('512763ac4e0559d0158b6682ca5dd1a3bd633f082f5e4349d7158e6b5f80f1ce'
            'f1733935c715db6d9e92bf9c76b75b4be7198f99ef4eecb6155890f8c64d0d4c'
            'e053dd9f647852e29967543f2a2944e9d10da679141a354e4269efd9d2163a28')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -Np1 -i "${srcdir}"/gvncviewer-1.2.0.patch
  patch -Np1 -i "${srcdir}"/001-fix-keymapgen-call.patch
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Dwith-vala=enabled \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson compile
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/meson test || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB"
}
